from flask import Flask,request

from email_utils import send_code

app = Flask(__name__)

code = 0
# 获取注册验证码
@app.route("/get_code")
def get_code():
    global code
    email = request.args.get("email")
    code = send_code(email)
    print(code)
    return str(code)

username = ""
password = ""
# 用户注册
@app.route("/reg")
def reg():
    global username
    global password
    username = request.args.get("username")
    print(username)
    password = request.args.get("password")
    print(password)
    user_code = request.args.get("code")
    print(user_code)
    print(code)
    if str(code) == str(user_code):
        return "注册成功"
    else:
        return "注册失败"

# 用户登录
@app.route("/login")
def login():
    username_param = request.args.get("username")
    password_param = request.args.get("password")
    if username == username_param and password_param == password:
        return "登录成功"
    else:
        return "用户名或者是密码错误"

if __name__ == "__main__":
    app.run()

